using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using way.model;

namespace way.util
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddAppDbContextFactory(this IServiceCollection services)
        {
            services.AddScoped<Func<string, AppDbContext>>(static serviceProvider =>
            {
                var dbOptions = serviceProvider.GetRequiredService<DbContextOptions<AppDbContext>>();
                return tableName => new AppDbContext(dbOptions, tableName);
            });
            return services;
        }
    }
}
